package com.jyh.db.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.jyh.db.entity.JyhChannelList;
import com.jyh.db.entity.JyhChannelListExample;
import com.jyh.db.mapper.JyhChannelListMapper;

@Repository
public class ChannelDao {
	@Autowired
	private JyhChannelListMapper channelMapper;

	/**
	 * 获取渠道并转义
	 * @return
	 */
	public Map<String, String> getChannel() {
		Map<String, String> mapChannel = new HashMap<String, String>();
		List<JyhChannelList> listChannel = channelMapper.selectByExample(new JyhChannelListExample());
		Map<String, String> map1 = new HashMap<String, String>();
		for (int i = 0; i < listChannel.size(); i++) {
			String generalize_id = listChannel.get(i).getGeneralizeId();
			String channelName = listChannel.get(i).getChannelname();
			map1.put(generalize_id, channelName);
		}

		for (int i = 0; i < listChannel.size(); i++) {
			String generalizeId = listChannel.get(i).getGeneralizeId();
			String channelNumber = listChannel.get(i).getChannelnumber();
			String name = map1.get(generalizeId.subSequence(0, 4))+"-";
			if (generalizeId.length() >= 8) {
				name += map1.get(generalizeId.subSequence(0, 8))+"-";
			}
			if (generalizeId.length() >= 12) {
				name += map1.get(generalizeId.subSequence(0, 12))+"-";
			}
			if (generalizeId.length() >= 16) {
				name += map1.get(generalizeId.subSequence(0, 16))+"-";
			}
			if (generalizeId.length() >= 20) {
				name += map1.get(generalizeId.subSequence(0, generalizeId.length()))+"-";
			}
			name = name.substring(0, name.length()-1);
			mapChannel.put(channelNumber, name);
		}
		return mapChannel;
	}
}
